package io.gitee.tziye.core.instance;

import io.gitee.tziye.enums.InstanceStatus;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

@Data
@NoArgsConstructor
public class RenaiInstance {

    private long id;
    private String instanceId;
    private String g;
    private String service;
    private String ip;
    private int port;
    private String status;
    private boolean leader;
    private Date createTime;
    private Date updateTime;

    public RenaiInstance(String instanceId, String ip, InstanceSpec instanceSpec) {
        this.instanceId = instanceId;
        this.ip = ip;
        this.g = instanceSpec.getGroup();
        this.service = instanceSpec.getService();
        this.port = instanceSpec.getPort();
    }

    public boolean isActive() {
        return InstanceStatus.Live.name().equalsIgnoreCase(status);
    }

}
